function update(id) {
    //alert(id)
    if (id == null) {
        return;
    }
    vm.showList = false;
    vm.title = "修改";
    vm.getInfo(id)

}

$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'school/school/schoolPredictor',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', index: 'id', width: 50, key: true, hidden: true},
            {label: '学校代码', name: 'code', index: 'code', width: 80},
            {label: '学校名称', name: 'name', index: 'name', width: 80},
            {label: '普通文科专业最低分', name: 'putongwenke', index: 'putongwenke', width: 80},
            {label: '普通理科专业最低分', name: 'putonglike', index: 'putonglike', width: 80},
            {label: '校企合作文科专业最低分', name: 'xiaoqihezuowenke', index: 'xiaoqihezuowenke', width: 80},
            {label: '校企合作理科专业最低分', name: 'xiaoqihezuolike', index: 'xiaoqihezuolike', width: 80},
            {label: '3+2连读文科专业最低分', name: 'lianduwenke', index: 'lianduwenke', width: 80},
            {label: '3+2连读理科专业最低分', name: 'liandulike', index: 'liandulike', width: 80},
            {label: '中外合作办学文科最低分', name: 'zhongwaihezuowenke', index: 'zhongwaihezuowenke', width: 80},
            {label: '中外合作办学理科最低分', name: 'zhongwaihezuolike', index: 'zhongwaihezuolike', width: 80},
            {label: '艺术文科最低分', name: 'yishuwenke', index: 'yishuwenke', width: 80},
            {label: '艺术理科最低分', name: 'yishulike', index: 'yishulike', width: 80},
            {label: '春考文科最低分', name: 'chunkaowenke', index: 'chunkaowenke', width: 80},
            {label: '春考理科最低分', name: 'chunkaolike', index: 'chunkaolike', width: 80},
            {label: '专科普通文科最低分', name: 'zhuankeputongwenke', index: 'zhuankeputongwenke', width: 80},
            {label: '专科普通理科最低分', name: 'zhuankeputonglike', index: 'zhuankeputonglike', width: 80},
            {label: '专科校企文科最低分', name: 'zhuankexiaoqiwenke', index: 'zhuankexiaoqiwenke', width: 80},
            {label: '专科校企理科最低分', name: 'zhuankexiaoqilike', index: 'zhuankexiaoqilike', width: 80},
            {label: '专科中外合作文科最低分', name: 'zhuankezhongwaihezuowenke', index: 'zhuankezhongwaihezuowenke', width: 80},
            {label: '专科中外合作理科最低分', name: 'zhuankezhongwaihezuolike', index: 'zhuankezhongwaihezuolike', width: 80},
            {
                label: '操作', name: 'id', width: 80,
                formatter: function (data) {
                    return '<span class="label label-default" onclick="update(' + data + ')">修改</span>';

                }
            }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        //  multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
        el: '#rrapp',
        data: {
            provinces: [],
            cities: [],
            q: {
                region: "",
                province: "",
                city: "",
                nature: "",
                level: ""
            },
            areas: [
                {
                    name: "华北",
                    provinces: []
                },
                {
                    name: "东北",
                    provinces: []
                },
                {
                    name: "华东",
                    provinces: []
                },
                {
                    name: "华中",
                    provinces: []
                },
                {
                    name: "西南",
                    provinces: []
                },
                {
                    name: "西北",
                    provinces: []
                }
            ],
            basicscore: {
                year: "",
                putongwenke: "0",
                putonglike: "0",
                xiaoqihezuowenke: "0",
                xiaoqihezuolike: "0",
                lianduwenke: "0",
                liandulike: "0",
                zhongwaihezuowenke: "0",
                zhongwaihezuolike: "0",
                yishuwenke: "0",
                yishulike: "0",
                chunkaowenke: "0",
                chunkaolike: "0",
                zhuankeputongwenke: "0",
                zhuankeputonglike: "0",
                zhuankexiaoqiwenke: "0",
                zhuankexiaoqilike: "0",
                zhuankelianduwenke: "0",
                zhuankeliandulike: "0",
                zhuankezhongwaihezuowenke: "0",
                zhuankezhongwaihezuolike: "0",
                zhuankeyishuwenke: "0",
                zhuankeyishulike: "0",
                zhuankechunkaowenke: "0",
                zhuankechunkaolike: "0"
            },
            showList: true,
            showChangeAll: false,
            title: null,
            school: {},
            area: null,
            learntype: [],
            change: {
                wenlike: "",
                score: 0,
            }
        },
        methods: {
            createPredictor: function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "basicscore/basicScore",
                    contentType: "application/json",
                    data: JSON.stringify(vm.basicscore),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功');
                            vm.showChangeAll = false;
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            closePredictor: function () {
                vm.showChangeAll = false;
            },
            query: function () {
                vm.reload();
            },
            add: function () {
                vm.showList = false;
                vm.title = "新增";
                vm.school = {
                    nature: "公办",
                    area: '济南',
                    enrolmentmethod: "夏考",
                    professionalcategory: "普通",
                    level: "本科",
                    learntype: ""

                };
            },
            update: function (event) {
                var id = getSelectedRow();
                if (id == null) {
                    return;
                }
                vm.showList = false;
                vm.title = "修改";

                vm.getInfo(id)
            },
            saveOrUpdate: function (event) {
                var url = "school/school/updatePredictor";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.school),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功', function (index) {
                                vm.reload();
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            del: function (event) {
                var ids = getSelectedRows();
                if (ids == null) {
                    return;
                }

                confirm('确定要删除选中的记录？', function () {
                    $.ajax({
                        type: "POST",
                        url: baseURL + "school/school/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function (r) {
                            if (r.code == 0) {
                                alert('操作成功', function (index) {
                                    $("#jqGrid").trigger("reloadGrid");
                                });
                            } else {
                                alert(r.msg);
                            }
                        }
                    });
                });
            },
            getInfo: function (id) {
                $.get(baseURL + "school/school/schoolPredictor/" + id, function (r) {
                    vm.school = r.school;
                });
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    page: page,
                    postData: {q: vm.q},
                }).trigger("reloadGrid");
            },
            changeALL: function () {
                confirm('确定要生成，这将覆盖掉你微调的所有数据？', function () {
                    $.ajax({
                        type: "POST",
                        url: baseURL + "school/school/changeALL",
                        contentType: "application/json",
                        data: JSON.stringify(vm.change),
                        success: function (r) {
                            if (r.code == 0) {
                                alert(r.msg);
                            } else {
                                alert(r.msg);
                            }
                        }
                    });
                });
            },
            ChangeRegion() {
                pa = {
                    'name': vm.q.region
                }
                $.ajax({
                    type: "POST",
                    url: baseURL + "school/provinceAndCities/getProvinces",
                    contentType: "application/json",
                    data: JSON.stringify(pa),
                    success: function (r) {
                        if (r.code === 0) {
                            vm.provinces = r.data
                            vm.reload()
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
            ChangeProvince() {
                pa = {
                    'name': vm.q.province
                }
                $.ajax({
                    type: "POST",
                    url: baseURL + "school/provinceAndCities/getCities",
                    contentType: "application/json",
                    data: JSON.stringify(pa),
                    success: function (r) {
                        if (r.code === 0) {
                            vm.cities = r.data
                            vm.reload()
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            },
        }
    })
;